package com.gsnd.gsnd22estore.web.controller;

import com.alipay.api.AlipayClient;
import com.gsnd.gsnd22estore.dto.QueryOrderDTO;
import com.gsnd.gsnd22estore.dto.extend.QueryOrderDTOExtend;
import com.gsnd.gsnd22estore.result.Result;
import com.gsnd.gsnd22estore.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    private AlipayClient alipayClient;

    @GetMapping
    public Result<List<QueryOrderDTO>> getOrder(@RequestParam(required = false) String id,
                                                @RequestParam(required = false) Integer status,
                                                HttpServletRequest request) {
        Integer userId = Integer.parseInt((String) request.getAttribute("userId"));
        return Result.success(orderService.getOrderByUser(userId, status, id));
    }
    @GetMapping("/{orderId}")
    public Result<QueryOrderDTOExtend> getOrderDetail(@PathVariable String orderId,
                                                      HttpServletRequest request){
        Integer userId = Integer.parseInt((String)request.getAttribute("userId"));
        return Result.success(orderService.getOrderDatailByUser(userId,orderId));
    }
}